/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package xq.gwt.mvc.controller;
import xq.gwt.mvc.model.ConversionException;
import xq.gwt.mvc.model.PropertyModel;
import xq.gwt.mvc.view.TextPropertyView;

/**
 *
 * @author admin
 */
public class TextPropertyController extends AbstractPropertyController{
    protected TextPropertyView textView;
    

    public TextPropertyController(TextPropertyView view){
        super(view);
        this.textView = view;
    }

    @Override
    public void setPropertyModel(PropertyModel model){
        super.setPropertyModel(model);
    }

    @Override
    public void updateModel() {
        try {
            textView.clearError();
            model.setText(textView.getText());
            if(model.getHasError()){
            	textView.setError("Invalid value");
            }
        } catch (ConversionException ex) {
            textView.setError(ex.getMessage());
        }
    }

    @Override
    public void updateView() {
        if (textView != null){
        	textView.clearError();
        	String val = model != null? model.getText() :null;        		
        	textView.setText(val);
        	
        }
    }

}
